package Servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import Services.AddFilmService;

/**
 * Servlet implementation class AddFilmServlet
 */
@WebServlet("/AddFilmServlet")
public class AddFilmServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddFilmServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		HttpSession session = request.getSession();
//		int memberID = (int)session.getAttribute("userid");
//		String filmName = request.getParameter("filmName");
//		String filmDesc = request.getParameter("filmDesc");
//		String filmGenre = request.getParameter("filmGenre");
//		
//		AddFilmService addFilmService = new AddFilmService();
//		int returncode = addFilmService.addFilm(filmName, filmDesc, filmGenre, memberID);
//		response.sendRedirect("getFilmServlet?r=" + returncode);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		//String stringMemberID = (String)session.getAttribute("userid");
		int memberID = 1;//Integer.parseInt(stringMemberID); CHANGE DIG BACK AFTA LOGIN AND SHIT SORTED
		String filmName = request.getParameter("filmName");
		String filmDesc = request.getParameter("filmDesc");
		String filmGenre = request.getParameter("filmGenre");
		
		AddFilmService addFilmService = new AddFilmService();
		System.out.println("Before addFilm is called");
		int returncode = addFilmService.addFilm(filmName, filmDesc, filmGenre, memberID);
		System.out.println("After addFilm is called");
		response.sendRedirect("getFilmServlet?r=" + returncode);
	}

}
